// lexicon_compiler.h
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright 2011 RWTH Aachen University. All Rights Reserved.
// Author: rybach@cs.rwth-aachen.de (David Rybach)

#ifndef LEXICON_COMPILER_H_
#define LEXICON_COMPILER_H_

#include <vector>
#include "fst/vector-fst.h"
#include "lexicon_transducer.h"

namespace trainc {

class HmmCompiler;

// Converts a LexiconTransducer to a fst::StdVectorFst.
// Input labels are generated by a given HmmCompiler.
class LexiconTransducerCompiler {
  typedef LexiconTransducer::Arc Arc;
  typedef LexiconTransducer::State State;
  typedef LexiconTransducer::StateId StateId;
public:
  LexiconTransducerCompiler()
      : l_(NULL), hmm_compiler_(NULL), boundary_phone_(-1) {}

  void SetTransducer(const LexiconTransducer *t) {
    l_ = t;
  }
  void SetHmmCompiler(const HmmCompiler *hmm_compiler) {
    hmm_compiler_ = hmm_compiler;
  }
  void SetBoundaryPhone(int boundary_phone) {
    boundary_phone_ = boundary_phone;
  }

  fst::StdVectorFst* CreateTransducer();

protected:
  fst::StdArc::Label GetInputLabel(const Arc &arc) const;
  void AddStartState(const std::vector<StateId> &states,
                     fst::StdVectorFst *result) const;

  const LexiconTransducer *l_;
  const HmmCompiler *hmm_compiler_;
  int boundary_phone_;
};

}  // namespace trainc

#endif  // LEXICON_COMPILER_H_
